package com.Rolin.wss.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.AsyncHandlerInterceptor;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class TicketInterceptor implements HandlerInterceptor {
    //引入日志
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        HttpSession session = request.getSession();
        Integer ticketNo = (Integer) session.getAttribute("Ticket");
        if(ticketNo == null) { //如果用户没选择票则跳转至选票页面
            response.sendRedirect(request.getContextPath()+"/features/doing/other");
            logger.info("拦截了Ticket为NULL的用户");
            return false;
        }else{
            logger.info("放行了Ticket为NULL的用户");
            return true;
        }
    }
}
